package com.submit.demo.controller;

import com.submit.demo.annotation.AuthIgnore;
import com.submit.demo.common.api.CommonPage;
import com.submit.demo.common.api.CommonResult;
import com.submit.demo.model.ColSub;
import com.submit.demo.model.Submitter;
import com.submit.demo.repository.ColSubRepository;
import com.submit.demo.service.ColSubService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("colsub")
public class ColSubController {
    @Autowired
    private ColSubRepository colSubRepository;

    @Autowired
    private ColSubService colSubService;

    @AuthIgnore
    @PostMapping("add")
    public CommonResult createColSub(String cid, String sid){
        ColSub colSub = new ColSub();
        colSub.setCid(cid);
        colSub.setSid(sid);
        List<String> tags = new ArrayList<>();
        tags.add("所有");
        colSub.setTags(tags);
        colSubRepository.insert(colSub);
        return CommonResult.success(null);
    }

    @ApiOperation("获取收集人管理的提交列表")
    @ResponseBody
    @RequestMapping(value = "/list")
    public CommonResult<CommonPage<Submitter>> getList(@RequestParam("cid") String cid, @RequestParam(defaultValue = "25") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNum){
        CommonPage<Submitter> list = colSubService.list(cid, pageNum, pageSize);
        return CommonResult.success(list);
    }
}
